package com.jy.wms.common.quartz;

import com.jy.wms.common.base.HttpUtil;
import com.jy.wms.common.base.ckfhInfo;
import com.jy.wms.service.WmsCustomerFileService;
import com.jy.wms.service.WmsGoodsAlarmService;
import com.jy.wms.service.WmsGoodsService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;

/**
 * 货品预警定时任务
 * @author liyi
 */
public class wmsGoodsAlarmScheduledJob implements Job {

    private WmsGoodsAlarmService wmsGoodsAlarmService;

    private WmsGoodsService wmsGoodsService;

    private WmsCustomerFileService wmsCustomerFileService;

    private static Logger log = LoggerFactory.getLogger(wmsGoodsAlarmScheduledJob.class);
    private SimpleDateFormat dateFormat() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        try {
            log.info("货品预警定时任_货品有效期预警启动时间：" + dateFormat().format(System.currentTimeMillis()));
            wmsGoodsAlarmService = (WmsGoodsAlarmService)dataMap.get("wmsGoodsAlarmService");
            //Integer count =  wmsGoodsAlarmService.baseInsertQuartz();
            //log.info("货品有效期预警加入：" + count + "条信息");
            //log.info("货品预警定时任_货品库存预警启动时间：" + dateFormat().format(System.currentTimeMillis()));
            //count = wmsGoodsAlarmService.baseInsertGoodsQuartz();
            //log.info("货品库存预警加入：" + count + "条信息");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("货品预警定时任异常");
            log.error(e.getMessage());
        }
        log.info("货品预警定时任_货品有效期预警结束时间：" + dateFormat().format(System.currentTimeMillis()));
        try {
            //获取商品基础信息
            log.info("商品基础信息定时器启动时间：" + dateFormat().format(System.currentTimeMillis()));
            wmsGoodsService = (WmsGoodsService)dataMap.get("wmsGoodsService");
            /*JSONObject jsonObject = JSONObject.fromObject(HttpUtil.doGet(ckfhInfo.quartz_getMateriual_url.getType()));
            if(jsonObject.get("backmsg").equals("success")){*/
                /*JSONArray jsonArray=new JSONArray();
                JSONObject jsonObject1=new JSONObject();
                jsonObject1.put("works","S.01");
                jsonObject1.put("volidate","1");
                jsonObject1.put("eaunit","本");
                jsonObject1.put("islotnumber","0");
                jsonObject1.put("mname","健康家生活（86期）");
                jsonObject1.put("matno","CZ05028");
                jsonObject1.put("temp2","");
                jsonObject1.put("group2","杂志/书籍类");
                jsonObject1.put("packno","1");
                jsonObject1.put("group1","CZ05");
                jsonObject1.put("temp1","");
                jsonArray.add(jsonObject1);*/
            /*JSONArray jsonArray=JSONArray.fromObject(jsonObject.get("backdetail").toString());
            log.info("商品基础信息大小：" + jsonArray.size());
            wmsGoodsService.getMateriual(jsonArray);
            }else{
            log.info("商品基础信息请求失败");
            }*/
        } catch (Exception e) {
            e.printStackTrace();
            log.error("商品基础信息定时任异常");
            log.error(e.getMessage());
        }
        log.info("商品基础信息定时器结束时间：" + dateFormat().format(System.currentTimeMillis()));
        try {
            //获取客户基础信息
           /*log.info("客户档案定时器启动时间：" + dateFormat().format(System.currentTimeMillis()));
           wmsCustomerFileService = (WmsCustomerFileService)dataMap.get("wmsCustomerFileService");
           JSONObject jsonObject = JSONObject.fromObject(HttpUtil.doPost(ckfhInfo.quartz_getCustomer_url.getType()));
           if(jsonObject.get("backmsg").equals("success")){
               JSONArray jsonArray=JSONArray.fromObject(jsonObject.get("backdetail").toString());
               log.info("客户档案获取大小：" + jsonArray.size());
               wmsCustomerFileService.getCustomer(jsonArray);
           }else{
                log.info("客户档案请求失败");
           }*/
        } catch (Exception e) {
            e.printStackTrace();
            log.error("客户档案定时任异常");
            log.error(e.getMessage());
        }
        log.info("客户档案定时器结束时间：" + dateFormat().format(System.currentTimeMillis()));
    }

   /* public static void main(String[] args) {
        JSONObject jsonObject = JSONObject.fromObject(HttpUtil.doGet("http://222.175.119.170:8001/wmsapi/easApi/getMateriual"));
        JSONObject jsonObject1 = JSONObject.fromObject(HttpUtil.doPost("http://222.175.119.170:8001/wmsapi/easApi/getCustomer"));
        if(jsonObject.get("backmsg").equals("success")){
            JSONArray jsonArray = JSONArray.fromObject(jsonObject.get("backdetail").toString());
            JSONArray jsonArray1 = JSONArray.fromObject(jsonObject1.get("backdetail").toString());
//            System.out.println("getMateriual=" + jsonArray.toString());
            System.out.println("getMateriual=" + jsonArray.size());
//            System.out.println("getCustomer=" + jsonArray1.toString());
            System.out.println("getCustomer=" + jsonArray1.size());
        }else{
            log.info("商品基础信息请求失败");
        }
    }*/
}